﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace OmniKits.Windows.Converters
{
    public class BooleanFalseToHiddenConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var tmp = value as bool?;
            if (!tmp.HasValue)
                return Visibility.Collapsed;
            else if (tmp.Value)
                return Visibility.Visible;
            else
                return Visibility.Hidden;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var tmp = (value as Visibility?).GetValueOrDefault(Visibility.Collapsed);
            if (tmp == Visibility.Visible)
                return true;
            else if (tmp == Visibility.Hidden)
                return false;
            else
                return null;
        }
    }
}
